#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <queue>
#include <stack>
#include <assert.h>

using namespace std;
typedef __int64 LONG; 

int k;
vector<string>	Dmd;

bool CanBeCenterRow(int cnt)
{
	for (int i=0; i<2*k-1; i++)
	{
		int sym = cnt +(cnt -i);
		if (sym == i || sym <0 || sym>=2*k-1)
			continue;

		for (int j=0; j<2*k-1; j++)
		{
			if (Dmd[i][j] == ' ' || Dmd[sym][j] == ' ' || Dmd[i][j] == Dmd[sym][j])
				continue;

			return false;
		}
	}

	return true;
}

bool CanBeCenterCol(int cnt)
{
	for (int i=0; i<2*k-1; i++)
	{
		int sym = cnt +(cnt -i);
		if (sym == i || sym <0 || sym>=2*k-1)
			continue;

		for (int j=0; j<2*k-1; j++)
		{
			if (Dmd[j][i] == ' ' || Dmd[j][sym] == ' ' || Dmd[j][i] == Dmd[j][sym])
				continue;

			return false;
		}
	}

	return true;

}

int CalcCost(int r, int c)
{
	int k0 =k + abs(k -1 -r);
	int k1 =k0+ abs(k -1 -c);

	return k1*k1 -k*k;
}

int FindMin()
{
	if (k == 1)
		return 0;

	int min = 99999999;
	int minr =-1;
	int minc = -1;

	for (int r =0; r<2*k-1; r++)
	{
		bool rowC =CanBeCenterRow(r);
		for (int c =0; c<2*k-1; c++)
		{
			if ( rowC && CanBeCenterCol(c))
			{
				int cost =CalcCost(r, c);			
				if (cost<min)
				{
					min = cost;
					minr =r;
					minc =c;
				}
			}
		}
	}

	return min;
}

void RunCase (ifstream& fin, ofstream& fout)
{
	fin>>k;
	Dmd.clear();

	for (int i=0; i<k*2-1; )
	{
		string s;
		getline(fin, s);

		if (!s.empty())
		{
			if (s.length()<k*2-1)
				s += string((k*2-1) -s.length(), ' ');
			Dmd.push_back(s);
			i++;
		}
	}

	int r =FindMin();
	fout<<r;
}

void RunAll(const char* fnameIn, const char* fnameOut)
{
	ifstream fin(fnameIn);
	ofstream fout(fnameOut);

	int caseCount;
	fin >> caseCount;

	for (int i=0; i<caseCount; i++)
	{
		fout<<"Case #"<<i+1<<": ";
		RunCase (fin, fout);
		fout<<"\n";
	}
}

void main()
{
	//RunAll("A-small-practice.in", "A-small-practice.out");
	RunAll("A-large-practice.in", "A-large-practice.out");

	return;
}